package com.koron.css2.serviceManage.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.serviceManage.bean.AccessoryTypeBean;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.mapper.AccessoryTypeMapper;
import com.koron.css2.serviceManage.queryBean.AccessoryTypeQueryBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

public class AccessoryTypeQuery implements ServerInterface{
	
private static Logger logger = LogManager.getLogger(AccessoryTypeQuery.class);
	
	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {

		@SuppressWarnings("rawtypes")
		MessageBean<AccessoryTypeBean> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "success", AccessoryTypeBean.class);

		try {
			AccessoryTypeQueryBean bean = JsonUtils.objectToPojo(req.getData(), AccessoryTypeQueryBean.class);
			AccessoryTypeMapper mapper = factory.getMapper(AccessoryTypeMapper.class);
			AccessoryTypeBean accessoryTypeBean = mapper.findAccessoryTypeById(bean.getAccessoryTypeId());
			
			info.setData( accessoryTypeBean);
		} catch (Exception e) {
			info.setCode(Constant.MESSAGE_INT_FAIL);
			info.setDescription(e.getMessage());
			logger.error(e.getMessage(), e);
		}
		return info;
	}

}
